<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="org.qiuqiu.pojo.User" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  
<script src="js/jquery.js"></script>
<script src="js/public.js"></script>
<script type="text/javascript">
var button=[true,true,true];
$(document).ready(function(){
	var sex = $("#sex").val();
   	if(sex=="男"){
   	   	$("#sex1").attr("checked","checked");
    }else if(sex=="女"){
           $("#sex2").attr("checked","checked");
    }
});

function checkFirstName(){
	var reg=/[\u4e00-\u9fa5a-zA-Z]/;
	var firstName = trim($("#firstName").val());
	if(/^[a-zA-Z ]{1,20}$/.test(firstName)||/^[\u4e00-\u9fa5]{1,10}$/.test(firstName)){
		$("#font1").attr("color","green");
		$("#font1").html("<img src=\"images/check_right.gif\"/>");
		buttoncheck(0,true);
	}else{
		$("#font1").attr("color","red");
		$("#font1").html("<img src=\"images/check_error.gif\"/>&nbsp;请输入正确的联系人的姓氏");
		buttoncheck(0,false);
	}
}

function checkSecondName(){
	var reg=/[\u4e00-\u9fa5a-zA-Z]/;
	var secondName = trim($("#secondName").val());
	if(/^[a-zA-Z ]{1,20}$/.test(secondName)||/^[\u4e00-\u9fa5]{1,10}$/.test(secondName)){
		$("#font2").attr("color","green");
		$("#font2").html("<img src=\"images/check_right.gif\"/>");
		buttoncheck(1,true);
	}else{
		$("#font2").attr("color","red");
		$("#font2").html("<img src=\"images/check_error.gif\"/>&nbsp;请输入正确的联系人的名字");
		buttoncheck(1,false);
	}
}

function checkEmail(){
	var email = $("#email").val();
	if(CheckEmail(email)){
		$("#font3").attr("color","green");
		$("#font3").html("<img src=\"images/check_right.gif\"/>&nbsp;电子邮件地址正确");
		buttoncheck(2,true);
	}else{
		$("#font3").attr("color","red");
		$("#font3").html("<img src=\"images/check_error.gif\"/>&nbsp;请输入正确的电子邮件地址");
		buttoncheck(2,false);
	}
}

function buttoncheck(index,bool){
	button[index]=bool;
	if(bool){
		for(var i=0;i<button.length;i++){
			if(!button[i]){
				return;
			}
		}
		document.getElementById("submit").disabled=false;
	}else{
		document.getElementById("submit").disabled=true;
	}
}

function send(){
	$.post("updateUser",{'user.firstName':$("#firstName").val(),'user.secondName':$("#secondName").val(),'user.sex':$("input[name=user.sex][checked]").val(),'user.email':$("#email").val()},function(data){
		if(data=="true"){
			window.parent.show_Message("修改个人信息成功!","green");
			window.parent.tb_remove();
		}else{
			window.parent.show_Message("修改个人信息失败,请稍后再试!","red");
			window.parent.tb_remove();
		}
	},"text")
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body background="images/bg2.gif">

      <table width="100%" border="1" align="center">
        <tr>
          <td width="20%"><div align="right">用户名：</div></td>
          <td width="40%"><input type="text" name="user.userName" id="userName"  value="${user.userName}" disabled="disabled"></td>
          <td width="40%"><font id="font" size="2" color="#808080">用户名不可修改</font></td>
        </tr>
        <tr>
          <td><div align="right">姓：</div></td>
          <td><input type="text" name="user.firstName" id="firstName"  onkeyup="checkFirstName()" value="${user.firstName}"></td>
          <td><font id="font1" size="2" color="#808080"><img src="images/check_right.gif"/></font></td>
        </tr>
		<tr>
          <td><div align="right">名：</div></td>
          <td><input type="text" name="user.secondName" id="secondName" onKeyUp="checkSecondName()" value="${user.secondName}"> </td>
          <td><font id="font2" size="2" color="#808080"><img src="images/check_right.gif"/></font></td>
        </tr>
        <tr>
          <td><div align="right">性别：</div></td>
          <td>
            <input type="radio" name="user.sex" id="sex1" value="男">男&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="user.sex" id="sex2" value="女">女
          </td>
          <td><font size="2" color="#808080">请选择修改性别</font></td>
        <tr>
          <td><div align="right">电子邮件：</div></td>
          <td><input type="text" name="user.email" id="email" onKeyUp="checkEmail()" value="${user.email}"></td>
          <td><font id="font3" size="2" color="#808080"><img src="images/check_right.gif"/></font></td>
        </tr>
		<tr>
          <td><div align="right">&nbsp;</div></td>
          <td><input type="submit" id="submit" value="确定" onClick="send()"/>&nbsp;&nbsp;&nbsp;<input type="reset" id="submit" value="重填" /></td>
          <td><font id="font2">&nbsp;</font><input type="hidden" id="sex" name="sex" value="${user.sex}"></td>
        </tr>
</table>
</body>
</html>
